// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial

// cSpell: ignore backtab

import { VerticalBox, ListView } from "std-widgets.slint";

TestCase := Window {
  width: 500px;
  height: 400px;

  property <[string]> features : [ "f" ];
  property <string> result;

  VerticalBox {
    VerticalBox {
      if true: ListView {
        for f in features: FocusScope {
          key-pressed(event) => {
              if (event.text == "X") {
                  result += "1:";
                  return accept;
              }
              return reject;
          }
        }
      }
      if false: Rectangle { }
    }
    FocusScope {
      key-pressed(event) => {
          if (event.text == "X") {
              result += "2:";
              return accept;
          }
          return reject;
      }
    }
  }
}

/*
```rust
let instance = TestCase::new().unwrap();

// Forward:
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "");
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "1:", "one tab");
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "1:2:", "two tab");
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "1:2:1:", "three tab");

instance.set_result("".into());

// Backwards:
slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "2:", "one backtab");
slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "2:1:", "two backtab");
slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq!(instance.get_result(), "2:1:2:", "three backtab");
```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;

// Forward:
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "");
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "1:");
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "1:2:");
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "1:2:1:");

instance.set_result("");

// Backwards:
slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "2:");
slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "2:1:");
slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
slint_testing::send_keyboard_string_sequence(&instance, "X");
assert_eq(instance.get_result(), "2:1:2:");
```

```js
var instance = new slint.TestCase();

// Forward:
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "");
slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "1:");
slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "1:2:");
slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "1:2:1:");

// Backwards:
instance.result = "";
assert.equal(instance.result, "");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "2:");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "2:1:");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
slintlib.private_api.send_keyboard_string_sequence(instance, "X");
assert.equal(instance.result, "2:1:2:");
```
*/
